// pages/aaa/aaa.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    openid:'',
    head:null,
    index:'点击头像',
    HeadUrl:'',
    array:[
      {
        img:'/img/zichan.png',
        image:'/img/r.png',
        title:'上传资产',
        body:'上传您的个人资产'
      },
      {
        img:'/img/personal.png',
        image:'/img/b.png',
        title:'购买记录',
        body:'购买记录明细'
      },
      {
        img:'/img/Assetstatus.png',
        image:'/img/d.png',
        title:'资产明细',
        body:'资产购买明细'
      },
      {
        img:'/img/customerservice.png',
        image:'/img/k.png',
        title:'我的客服',
      },
    ],
    HeadUrl:'',
    NickName:'',
  },
  user:function(){
    wx.request({
      url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=users',
      method:'POST',
      success:(res)=>{
        console.log(res);
      }
    })
  },
  get:function(){
    var that= this;
    wx.getStorage({
      key: 'key',
      success:(res)=>{
        that.setData({
          HeadUrl:res.data.avatarUrl,
          NickName:res.data.nickName
        })
        that.onShow();
        // console.log(that.data.openid);
      }
    })
    
  },
  login:function(e){//获取用户头像和名字
    var that = this;
    wx.getUserProfile({
      desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (file) => {
  //       console.log(file)
      wx.setStorage({
        data: file.userInfo,
        key: 'key',
      })
      that.get();
        wx.login({
          success: (res) => {
            console.log(res.code);
            wx.request({
              url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=code',
              method:'POST',
              data: {
                code: res.code,
              },
              success: (open) => {
              wx.request({
                url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=week_ins',
                method:'POST',
                data:{
                  openid:open.data.openid
                },
                success:function(e){
                  wx:wx.request({
                    url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=eco_ins',
                    method:'POST',
                    data:{
                      openid:open.data.openid
                    },

                    success: (result) => {
                    console.log(result);
                    },
                    
                  })
                    console.log(e)
                },
              })
  //               console.log(open.data);
                 wx.setStorage({
                      data: open.data.openid,
                      key: 'open',
                 })
                wx.request({
                  url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=users_ins',
                  method:'POST',
                  data: {
                      openid: open.data.openid,
                      NickName: file.userInfo.nickName,
                      HeadUrl: file.userInfo.avatarUrl,
                      country: file.userInfo.country,
                      gender: file.userInfo.gender
                  },
                  success(data) {
  //                   console.log(data);
                   
  //                   请求用户信息
                    // 本地
                  }
                })
              }
            })
          }
        })
      }
    })
   },
  Jump:function(e){//跳转
    console.log(e.currentTarget.dataset.index);
    var a=e.currentTarget.dataset.index;
    if (a==0) {
      wx.reLaunch({
        url: '/pages/release/release',
      })
    }else if(a==1){
      wx.reLaunch({
        url: '/pages/details/details',
      })
    }else if(a==2){
      wx.reLaunch({
        url: '/pages/detailed/detailed',
      })
    }else if(a==3){
      wx.navigateTo({
        url: '/pages/dd/dd',
      })
    }
    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    // console.log(this.openid);
    that.get();
    console.log(that.openid);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})